﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;

namespace PMS.XCMG.Entity
{
    /// <summary>
    /// 生产单元
    /// </summary>
    public partial class WorkshoUnit : BusEntity
    {
        /// <summary>
        /// 生产区域ID
        /// </summary>
        public string AreaId { set; get; }
        /// <summary>
        /// 生产单元编码
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 生产单元名称
        /// </summary>
        public string Name { get; set; }
    }

    public partial class WorkshoUnit : BusEntity
    {
        /// <summary>
        /// 所属生产区域
        /// </summary>
        public WorkshoArea Area { set; get; }
        /// <summary>
        /// 生产单元下的工作
        /// </summary>
        public List<WorkshoStation> Stations { set; get; }
    }

    /// <summary>
    /// 实体配置
    /// OnModelCreating
    /// </summary>
    public class WorkshoUnitTypeConfig : BusEntityTypeConfig<WorkshoUnit>, IEntityTypeConfiguration<WorkshoUnit>
    {
        public override void Configure(EntityTypeBuilder<WorkshoUnit> builder)
        {
            base.Configure(builder);

            #region 主外键关系
            builder.HasOne(p => p.Area).WithMany(p => p.Units).HasForeignKey(p => p.AreaId);
            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.AreaId).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Code).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            builder.Property(p => p.Name).HasMaxLength(EntityDefinition.DefSmallColLen).IsRequired();
            #endregion

            #region 备注
            builder.HasComment("生产单元");
            builder.Property(p => p.AreaId).HasComment("生产区域ID");
            builder.Property(p => p.Code).HasComment("生产单元编码");
            builder.Property(p => p.Name).HasComment("生产单元名称");
            #endregion

            #region 种子数据
            builder.HasData(new WorkshoUnit() { Id = "C91001001", AreaId = "C91001", Name = "叶片分拣单元", Code = "C91001001", CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new WorkshoUnit() { Id = "LLHCQ_SXBFL", AreaId = "LLHCQ", Name = "扇形板发料单元", Code = "01.LLHCQ_SXBFLDY", CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new WorkshoUnit() { Id = "LLHCQ_ZTBFL", AreaId = "LLHCQ", Name = "中筒板发料单元", Code = "01.LLHCQ_ZTBFLDY", CreateUserId = "1", ModifyUserId = "1" });

            //builder.HasData(new WorkshoUnit() { Id = "PBJYQ_ZTXPH", AreaId = "PBJYQ", Name = "锥筒拼焊(小)单元", Code = "01.PBJYQ_ZTXPHDY", CreateUserId = "1", ModifyUserId = "1" });
            //builder.HasData(new WorkshoUnit() { Id = "PBJYQ_ZTDPH", AreaId = "PBJYQ", Name = "锥筒拼焊(大)单元", Code = "02.PBJYQ_ZTDPHDY", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoUnit() { Id = "C91002001", AreaId = "C91002", Name = "拼板单元", Code = "C91002001", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoUnit() { Id = "C91002002", AreaId = "C91002", Name = "卷圆单元", Code = "C91002002", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoUnit() { Id = "C91003001", AreaId = "C91003", Name = "纵缝焊接单元", Code = "C91003001", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoUnit() { Id = "C91003002", AreaId = "C91003", Name = "前锥组对单元", Code = "C91003002", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoUnit() { Id = "C91003003", AreaId = "C91003", Name = "后锥压装单元", Code = "C91003003", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoUnit() { Id = "C91004001", AreaId = "C91004", Name = "立式组对单元", Code = "C91004001", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoUnit() { Id = "C91004002", AreaId = "C91004", Name = "内环缝焊单元", Code = "C91004002", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoUnit() { Id = "C91004003", AreaId = "C91004", Name = "叶片摆搭单元", Code = "C91004003", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoUnit() { Id = "C91004004", AreaId = "C91004", Name = "叶片满焊单元", Code = "C91004004", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoUnit() { Id = "C91004005", AreaId = "C91004", Name = "筒体合模单元", Code = "C91004005", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoUnit() { Id = "C91004006", AreaId = "C91004", Name = "合模满焊单元", Code = "C91004005", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoUnit() { Id = "C91004007", AreaId = "C91004", Name = "外环缝焊单元", Code = "C91004006", CreateUserId = "1", ModifyUserId = "1" });
            builder.HasData(new WorkshoUnit() { Id = "C91004008", AreaId = "C91004", Name = "人工补焊单元", Code = "C91004007", CreateUserId = "1", ModifyUserId = "1" });

            builder.HasData(new WorkshoUnit() { Id = "C91005001", AreaId = "C91005", Name = "筒体检测单元", Code = "C91005001", CreateUserId = "1", ModifyUserId = "1" });
            #endregion
        }
    }
}
